<?php

namespace Tests\Browser\App;

use App\Services\Utils\TimeHelper;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\DuskTestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\Utils\PanxData;

abstract class AppPageTestCase extends DuskTestCase
{
    use DatabaseMigrations,
        WithFaker;

    protected $screen_short_dir = 'app';

    protected function setUp()
    {
        parent::setUp();

        config([PanxData::DUSK_ENV_KEY => PanxData::DUSK_ENV_APP]);

        $this->tryMakeScreenShotDir();
    }

    final private function tryMakeScreenShotDir(): void
    {
        $in_dir = $this->screen_short_dir;
        $dir = base_path("tests/Browser/screenshots/{$in_dir}");

        if (! is_dir($dir)) {
            mkdir($dir, 0777, true);
        }
    }

    protected function toCaptureTimestamp(string $prefix = null): string
    {
        if (! $prefix) {
            $prefix = class_basename(static::class);
        }

        return $this->screen_short_dir . '/' . $prefix . '_' . TimeHelper::toFileSuffix();
    }
}
